Published 2004-09-07 21:36:14
$hightlight = 0;
while ($do->fetch()) {
$r = clone($do);
$r->highlight = "row" . ((int) $highlight);
$hightlight = !$highlight;
$this->rows[] = $r;
}
<tr flexy:foreach="rows,row" class="{row.highlight}">
<td>{row.somedata}</td>
...
</tr>
Ok, that wasnt too bad, but somehow the messing around in PHP each time, just to do the highlighting felt kind of messy.., I had looked at this again recently for another project, and discovered there is a way to do it using CSS2 (but IE doesnt support it.. - what a supprise). I had also seen another suggestion, adding a behaviour to the style for the table, this seemed reasonable, however, when I'm prototyping, I like to keep things together, so it was a bit annoying to have this loose bit of javascript hanging around in a file on it's own.while ($do->fetch()) {And in the template:
$this->rows[] = clone($do);
}
<script type="text/javascript">
function highlightTables()
{
var tables=document.getElementsByType('table');
for (var t = 0; t < tables.length; t++) {
if (tables[t].getAttribute('class') != 'stripes') {
continue;
}
oRows = tables[t].rows;
var len = oRows.length;
for (i=1; i<oRows.length; i++) {
oRows[i].setAttribute("class",
(oRows[i].rowIndex % 2) ? 'row1' : 'row0');
}
}
}
// run it on load, or just call the function when you startup.
window.onload = hightlightTables
</script>
<tr flexy:foreach="rows,row" class="stripes">
<td>{row.somedata}</td>
...
</tr>